/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.ZAttributes;
/*     */ import com.zimbra.cs.ldap.ZMutableEntry;
/*     */ import com.zimbra.qa.unittest.prov.BinaryLdapData.Content;
/*     */ import java.util.Arrays;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapZMutableEntry
/*     */   extends LdapTest
/*     */ {
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {}
/*     */   
/*     */   @Test
/*     */   public void setAttr()
/*     */     throws Exception
/*     */   {
/*  43 */     String KEY = "key";
/*  44 */     String VALUE1 = "value1";
/*  45 */     String VALUE2 = "value2";
/*     */     
/*  47 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/*     */     
/*  49 */     entry.setAttr(KEY, VALUE1);
/*  50 */     entry.setAttr(KEY, VALUE2);
/*     */     
/*  52 */     ZAttributes zattrs = entry.getAttributes();
/*  53 */     Map<String, Object> attrs = zattrs.getAttrs();
/*     */     
/*  55 */     Object valueGot = attrs.get(KEY);
/*  56 */     Assert.assertTrue(valueGot instanceof String);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void addAttr() throws Exception {
/*  61 */     String KEY = "key";
/*  62 */     String VALUE1 = "value1";
/*  63 */     String VALUE2 = "value2";
/*  64 */     String VALUE3 = "value3";
/*     */     
/*  66 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/*     */     
/*  68 */     Set<String> values = new HashSet();
/*  69 */     values.add(VALUE1);
/*  70 */     values.add(VALUE2);
/*  71 */     entry.addAttr(KEY, values);
/*     */     
/*  73 */     values.clear();
/*  74 */     values.add(VALUE1);
/*  75 */     values.add(VALUE3);
/*  76 */     entry.addAttr(KEY, values);
/*     */     
/*  78 */     ZAttributes zattrs = entry.getAttributes();
/*  79 */     Map<String, Object> attrs = zattrs.getAttrs();
/*     */     
/*  81 */     Object valueGot = attrs.get(KEY);
/*  82 */     Assert.assertTrue(valueGot instanceof String[]);
/*  83 */     List<String> valuesGot = Arrays.asList((String[])valueGot);
/*  84 */     Assert.assertTrue(valuesGot.contains(VALUE1));
/*  85 */     Assert.assertTrue(valuesGot.contains(VALUE2));
/*  86 */     Assert.assertTrue(valuesGot.contains(VALUE3));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAttrString() throws Exception {
/*  91 */     String KEY = "key";
/*  92 */     String VALUE1 = "value1";
/*  93 */     String VALUE2 = "value2";
/*     */     
/*  95 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/*  96 */     entry.setAttr(KEY, VALUE1);
/*     */     
/*     */ 
/*  99 */     String valueGot = entry.getAttrString(KEY);
/* 100 */     Assert.assertEquals(VALUE1, valueGot);
/*     */     
/*     */ 
/* 103 */     Set<String> values = new HashSet();
/* 104 */     values.add(VALUE2);
/* 105 */     entry.addAttr(KEY, values);
/* 106 */     valueGot = entry.getAttrString(KEY);
/*     */     
/*     */ 
/* 109 */     Assert.assertTrue((VALUE1.equals(valueGot)) || (VALUE2.equals(valueGot)));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void hasAttribute() throws Exception {
/* 114 */     String KEY = "key";
/* 115 */     String VALUE1 = "value1";
/*     */     
/* 117 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/*     */     
/* 119 */     entry.setAttr(KEY, VALUE1);
/* 120 */     Assert.assertTrue(entry.hasAttribute(KEY));
/* 121 */     Assert.assertFalse(entry.hasAttribute(KEY + "-NOT"));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void mapToAttrsSimple() throws Exception
/*     */   {
/* 127 */     String KEY_SINGLE = "key";
/* 128 */     String KEY_MULTI = "key-multi";
/* 129 */     String VALUE1 = "value1";
/* 130 */     String VALUE2 = "value2";
/*     */     
/* 132 */     Map<String, Object> attrMap = new HashMap();
/*     */     
/*     */ 
/* 135 */     attrMap.put(KEY_SINGLE, VALUE1);
/*     */     
/*     */ 
/* 138 */     attrMap.put(KEY_MULTI, new String[] { VALUE1, VALUE2 });
/*     */     
/* 140 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/* 141 */     entry.mapToAttrs(attrMap);
/*     */     
/*     */ 
/* 144 */     String valueGot = entry.getAttrString(KEY_SINGLE);
/* 145 */     Assert.assertEquals(VALUE1, valueGot);
/*     */     
/*     */ 
/* 148 */     ZAttributes zattrs = entry.getAttributes();
/* 149 */     Map<String, Object> attrs = zattrs.getAttrs();
/* 150 */     Object multiValueGot = attrs.get(KEY_MULTI);
/* 151 */     Assert.assertTrue(multiValueGot instanceof String[]);
/* 152 */     List<String> valuesGot = Arrays.asList((String[])multiValueGot);
/* 153 */     Assert.assertTrue(valuesGot.contains(VALUE1));
/* 154 */     Assert.assertTrue(valuesGot.contains(VALUE2));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void mapToAttrsBinarySingle() throws Exception {
/* 159 */     int NUM_BYTES_IN_BINARY_DATA = 64;
/*     */     
/* 161 */     String KEY_SINGLE_BINARY = "userSMIMECertificate";
/* 162 */     String KEY_SINGLE_BINARY_TRANSFER = "userCertificate";
/*     */     
/* 164 */     BinaryLdapData.Content VALUE_BINARY = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
/*     */     
/* 166 */     BinaryLdapData.Content VALUE_BINARY_TRANSFER = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
/*     */     
/*     */ 
/* 169 */     Map<String, Object> attrMap = new HashMap();
/*     */     
/* 171 */     attrMap.put(KEY_SINGLE_BINARY, VALUE_BINARY.getString());
/* 172 */     attrMap.put(KEY_SINGLE_BINARY_TRANSFER, VALUE_BINARY_TRANSFER.getString());
/*     */     
/* 174 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/* 175 */     entry.mapToAttrs(attrMap);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 194 */     Map<String, Object> attrMapGot = entry.getAttributes().getAttrs();
/* 195 */     Object valueGot = attrMapGot.get(KEY_SINGLE_BINARY);
/* 196 */     Assert.assertTrue(valueGot instanceof String);
/* 197 */     Assert.assertTrue(((String)valueGot).equals(VALUE_BINARY.getString()));
/*     */     
/*     */ 
/* 200 */     attrMapGot = entry.getAttributes().getAttrs();
/* 201 */     valueGot = attrMapGot.get(KEY_SINGLE_BINARY_TRANSFER);
/* 202 */     Assert.assertTrue(valueGot instanceof String);
/* 203 */     Assert.assertTrue(((String)valueGot).equals(VALUE_BINARY_TRANSFER.getString()));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void mapToAttrsBinaryMulti() throws Exception {
/* 208 */     int NUM_BYTES_IN_BINARY_DATA = 64;
/*     */     
/* 210 */     String KEY_MULTI_BINARY = "userSMIMECertificate";
/* 211 */     String KEY_MULTI_BINARY_TRANSFER = "userCertificate";
/*     */     
/* 213 */     BinaryLdapData.Content VALUE_BINARY_1 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
/*     */     
/* 215 */     BinaryLdapData.Content VALUE_BINARY_2 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
/*     */     
/* 217 */     BinaryLdapData.Content VALUE_BINARY_TRANSFER_1 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
/*     */     
/* 219 */     BinaryLdapData.Content VALUE_BINARY_TRANSFER_2 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
/*     */     
/*     */ 
/* 222 */     Map<String, Object> attrMap = new HashMap();
/*     */     
/* 224 */     attrMap.put(KEY_MULTI_BINARY, new String[] { VALUE_BINARY_1.getString(), VALUE_BINARY_2.getString() });
/*     */     
/* 226 */     attrMap.put(KEY_MULTI_BINARY_TRANSFER, new String[] { VALUE_BINARY_TRANSFER_1.getString(), VALUE_BINARY_TRANSFER_2.getString() });
/*     */     
/*     */ 
/*     */ 
/* 230 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/* 231 */     entry.mapToAttrs(attrMap);
/*     */     
/*     */ 
/* 234 */     Map<String, Object> attrMapGot = entry.getAttributes().getAttrs();
/* 235 */     Object valueGot = attrMapGot.get(KEY_MULTI_BINARY);
/* 236 */     Assert.assertTrue(valueGot instanceof String[]);
/* 237 */     List<String> valuesGot = Arrays.asList((String[])valueGot);
/* 238 */     Assert.assertTrue(valuesGot.contains(VALUE_BINARY_1.getString()));
/* 239 */     Assert.assertTrue(valuesGot.contains(VALUE_BINARY_2.getString()));
/*     */     
/*     */ 
/* 242 */     attrMapGot = entry.getAttributes().getAttrs();
/* 243 */     valueGot = attrMapGot.get(KEY_MULTI_BINARY_TRANSFER);
/* 244 */     Assert.assertTrue(valueGot instanceof String[]);
/* 245 */     valuesGot = Arrays.asList((String[])valueGot);
/* 246 */     Assert.assertTrue(valuesGot.contains(VALUE_BINARY_TRANSFER_1.getString()));
/* 247 */     Assert.assertTrue(valuesGot.contains(VALUE_BINARY_TRANSFER_2.getString()));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void setDN() throws Exception {
/* 252 */     String DN = "cn=zimbra";
/* 253 */     ZMutableEntry entry = LdapClient.createMutableEntry();
/* 254 */     entry.setDN(DN);
/* 255 */     Assert.assertEquals(DN, entry.getDN());
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapZMutableEntry.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */